package com.gufe.mapper.user.excellentperson;

import com.gufe.entity.excellentperson.ExcellentImage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExcellentImageMapper {
    @Insert("INSERT INTO excellent_images (excellent_personnel_id, image_path) VALUES (#{excellentpersonnelId}, #{imagePath})")
    int insert(ExcellentImage image);

    @Select("SELECT id, excellent_personnel_id, image_path FROM excellent_images WHERE excellent_personnel_id = #{excellentpersonnelId}")
    List<ExcellentImage> selectByPersonnelId(Integer personnelId);

    @Delete("DELETE FROM excellent_images WHERE excellent_personnel_id = #{excellentpersonnelId}")
    int deleteByPersonnelId(Integer personnelId);

    @Delete("DELETE FROM excellent_images WHERE id = #{id}")
    int deleteById(Integer id);

    @Insert("<script>" +
            "INSERT INTO excellent_images (excellent_personnel_id, image_path) VALUES " +
            "<foreach item='path' collection='imagePaths' separator=','>" +
            "(#{excellentpersonnelId}, #{path})" +
            "</foreach>" +
            "</script>")
    int insertBatch(@Param("personnelId") Integer personnelId, @Param("imagePaths") List<String> imagePaths);

    @Delete("DELETE FROM excellent_images WHERE excellent_personnel_id = #{excellentpersonnelId} AND image_path NOT IN " +
            "(<foreach item='path' collection='imagePaths' separator=','>#{path}</foreach>)")
    int deleteOldImages(@Param("personnelId") Integer personnelId, @Param("imagePaths") List<String> imagePaths);
}